import dayjs from 'dayjs';

export default function(app) {
    let formatString = "YYYY-MM-DD HH:mm:ss";
    
    app.directive("form-time", {
        created(el, bindings) {
            if(bindings.value) {
                formatString = bindings.value;
            }
        },
        mounted(el) {
            // console.log(el.textContent)
            const { textContent } = el;
            let timestamp = parseInt(textContent);  //转数字
            
            //对单位做一个统一  10位是秒 13位是毫秒
            if(textContent.length === 10) {
                timestamp = timestamp * 1000;
            }

            el.textContent = dayjs(timestamp).format(formatString)
        },
    })
}